﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmiEmuLib.Configuration.AmigaEventsConfig;
using System.Xml;
using TomanuExtensions;

namespace AmiEmuLib.Configuration.KeyboardConfig
{
    /// <summary>
    /// Bind amiga event with raw code.
    /// </summary>
    public class RawCode
    {
        /// <summary>
        /// Amiga event that generates raw code.
        /// </summary>
        public readonly AmigaEvent AmigaEvent;

        /// <summary>
        /// Raw code generate by amiga event.
        /// </summary>
        public readonly byte ScanCode;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="a_reader"></param>
        internal RawCode(XmlReader a_reader)
        {
            ScanCode = a_reader.GetAttributeHexByte("ScanCode");
            AmigaEvent = AmigaEventsList.GetEvent(a_reader.GetAttribute("AmigaEvent"));

            a_reader.MoveToNextElement(GetType().Name);
        }

        /// <summary>
        /// Write xml.
        /// </summary>
        /// <param name="a_writer"></param>
        internal void WriteXml(XmlWriter a_writer)
        {
            a_writer.WriteStartElement(GetType().Name);

            a_writer.WriteHexAttribute("ScanCode", ScanCode);
            a_writer.WriteAttribute("AmigaEvent", AmigaEvent.Name);

            a_writer.WriteEndElement();
        }
    }
}
